package org.xm.sk.vo.tb;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.xm.sk.vo.Base;
import org.xm.sk.vo.e.BoderStatus;

import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
@Table(name = "dc_order")
@ApiModel(value = "Boder", parent = Base.class, description = "订单")
public class Boder extends Base {

    /**
     * 
     */
    private static final long serialVersionUID = -6140361346504182121L;

    @ApiModelProperty(value = "订单名称")
    @Column(length = 255)
    private String name;

    @ApiModelProperty(value = "订单使用的优惠券")
    @JsonIgnore
    @ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinColumn(name = "dc_coupon_id")
    private Coupon coupon;

    @ApiModelProperty(value = "订单使用的优惠券ID")
    @Transient
    private Integer couponId;

    @ApiModelProperty(value = "订单关联的门店")
    @JsonIgnore
    @ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinColumn(name = "dc_shop_id")
    private Shop shop;

    @ApiModelProperty(value = "订单关联的门店ID")
    @Transient
    private Integer shopId;

    @ApiModelProperty(value = "订单关联的发型师")
    @JsonIgnore
    @ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinColumn(name = "dc_hairdresser_id")
    private Hairdresser hairdresser;

    @ApiModelProperty(value = "订单关联的发型师ID")
    @Transient
    private Integer hairdresserId;

    @ApiModelProperty(value = "订单项目集")
    @JsonIgnore
    @ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinTable(name = "dc_order_item", joinColumns = {
            @JoinColumn(name = "dc_order_id") }, inverseJoinColumns = {
                    @JoinColumn(name = "dc_item_id") })
    @Fetch(FetchMode.SUBSELECT)
    private Set<Item> items = new HashSet<Item>(0);

    @ApiModelProperty(value = "订单价格ID集")
    @Transient
    private Set<Integer> itemIds = new HashSet<Integer>(0);

    @ApiModelProperty(value = "订单价格集")
    @JsonIgnore
    @ManyToMany(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinTable(name = "dc_order_price", joinColumns = {
            @JoinColumn(name = "dc_order_id") }, inverseJoinColumns = {
                    @JoinColumn(name = "dc_price_id") })
    @Fetch(FetchMode.SUBSELECT)
    private Set<Price> prices = new HashSet<Price>(0);

    @ApiModelProperty(value = "订单价格ID集")
    @Transient
    private Set<Integer> priceIds = new HashSet<Integer>(0);

    @ApiModelProperty(value = "订单关联客户")
    @JsonIgnore
    @ManyToOne(cascade = { CascadeType.MERGE }, fetch = FetchType.LAZY)
    @JoinColumn(name = "dc_user_id")
    private User user;

    @ApiModelProperty(value = "订单关联的客户ID")
    @Transient
    private Integer userId;
    
    @ApiModelProperty(value = "订单关联的客户名")
    @Transient
    private String userName;

    @ApiModelProperty(value = "订单号")
    @Column(length = 255)
    private String ordernum;

    @ApiModelProperty(value = "订单状态")
    @Enumerated(value = EnumType.ORDINAL)
    @Column
    private BoderStatus status;

    @ApiModelProperty(value = "订单项目名称集字符串")
    @Column(length = 255)
    private String itemNames;

    @ApiModelProperty(value = "订单关联门店名称")
    @Column(length = 255)
    private String shopName;

    @ApiModelProperty(value = "订单关联发型师名称")
    @Column(length = 255)
    private String hairdresserName;

    @ApiModelProperty(value = "订单价格值")
    @Column
    private Double priceValue;

    @ApiModelProperty(value = "订单使用优惠券号")
    @Column(length = 20)
    private String couponnum;

    @ApiModelProperty(value = "优惠券抵用价")
    @Column
    private Double couponValue;

    @ApiModelProperty(value = "订单预留联系电话")
    @Column(length = 20)
    private String phone;

    @ApiModelProperty(value = "订单预留联系地址")
    @Column(length = 255)
    private String address;

    @ApiModelProperty(value = "订单支付价格")
    @Column
    private Double pay;

    @ApiModelProperty(value = "订单关联发型师所得佣金")
    @Column
    private Double brokerage;
    
    @ApiModelProperty(value = "订单预约时间")
    @Column
    private Date mktime;
    
    @ApiModelProperty(value = "订单服务时间")
    @Column
    private Date svtime;
    
    @ApiModelProperty(value = "订单付款时间")
    @Column
    private Date pytime;

    @ApiModelProperty(value = "微信预支付编号")
    @Column
    private String prepayId;

    @ApiModelProperty(value = "核销码")
    @Column
    private String verificode;

    @ApiModelProperty(value = "订单下的评论")
    @JsonIgnore
    @OneToMany(cascade = {
            CascadeType.MERGE }, fetch = FetchType.LAZY, mappedBy = "boder")
    @Fetch(FetchMode.SUBSELECT)
    private Set<Mete> metes = new HashSet<Mete>(0);
    
}
